// The Vue build version to loading with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import promise from 'es6-promise'
import store from './store'
import { Toast } from 'vant'
// set rem
import 'lib-flexible'
// set prototype
import hmTool from './assets/js/hmTool'
import appTool from './assets/js/appTool'
import axios from 'axios'
import { cancelObj } from './utils/fetch'
import api from './api/mergeApi'
// style
import './assets/css/base.css'
import 'vant/lib/index.css'
import './assets/css/vant.css'
import './assets/css/fontSize.css'
import './assets/css/color.css'

// use
promise.polyfill()
Vue.config.productionTip = false
Vue.prototype.$hqTool = hmTool
Vue.prototype.$appTool = appTool
Vue.prototype.$api = api
Vue.use(Toast)
// 动态title
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  // 切换路由取消上个路由的所有请求
  const CancelToken = axios.CancelToken
  cancelObj.source.cancel && cancelObj.source.cancel()
  cancelObj.source = CancelToken.source()
  // all
  next()
})
/* eslint-disable no-new */
window.Vm = new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
